const request = require('request');
const fs = require('fs');

let n = 0;
const max = 50;

const img = [];

function downloadPic(src, dest) {
    request(src).pipe(fs.createWriteStream(dest)).on('close', function(err) {
        n += 1;
        if (!err) {
            console.log('download success');
        } else {
            console.log(err);
            process.exit();
        }

        if (n === max) {
            console.log(img);
            fs.writeFileSync('src/assets/imgList.js', `export default ${JSON.stringify(img)}`);
        }
    });
}

for (let i = 0; i < max; i++) {
    const path = `public/codeImage/${i}.jpg`;
    img.push(path.replace(/public\//g, ''));
    downloadPic('https://picsum.photos/300/150', path);
}
